﻿using System.Text;

namespace CodeMinder.Output.MotionChart.Entities
{
    public class Options : IScriptable
    {
        #region Properties
        public int Width { get; set; }
        public int Height { get; set; }
        public State State { get; set; }
        public bool ShowChartButtons { get; set; }
        public bool ShowHeader { get; set; }
        public bool ShowSelectListComponent { get; set; }
        public bool ShowSidePanel { get; set; }
        public bool ShowXMetricPicker { get; set; }
        public bool ShowYMetricPicker { get; set; }
        public bool ShowXScalePicker { get; set; }
        public bool ShowYScalePicker { get; set; }
        public bool ShowAdvancedPanel { get; set; }
        #endregion

        #region Ctor
        public Options()
        {
            SetToGoogleDefaultValues();
        }

        private void SetToGoogleDefaultValues()
        {
            Width = 500;
            Height = 300;
            ShowChartButtons = true;
            ShowHeader = true;
            ShowSelectListComponent = true;
            ShowSidePanel = true;
            ShowXMetricPicker = true;
            ShowYMetricPicker = true;
            ShowXScalePicker = true;
            ShowYScalePicker = true;
            ShowAdvancedPanel = true;
        }
        #endregion

        #region IScriptable Members
        public virtual string ToScript()
        {
            const string optionFormat = @"options['{0}'] = {1};";

            var scriptBuilder = new StringBuilder();
            scriptBuilder.AppendLine(@"var options = {};");

            if (Width != 500)
                scriptBuilder.AppendLine(string.Format(optionFormat, "width", Width));

            if (Height != 300)
                scriptBuilder.AppendLine(string.Format(optionFormat, "height", Height));

            if (State != null)
                scriptBuilder.AppendLine(string.Format(optionFormat, "state", State.ToScript()));

            if (!ShowChartButtons)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showChartButtons", ShowChartButtons.ToString().ToLower()));

            if (!ShowHeader)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showHeader", ShowHeader.ToString().ToLower()));

            if (!ShowSelectListComponent)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showSelectListComponent", ShowSelectListComponent.ToString().ToLower()));

            if (!ShowSidePanel)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showSidePanel", ShowSidePanel.ToString().ToLower()));

            if (!ShowXMetricPicker)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showXMetricPicker", ShowXMetricPicker.ToString().ToLower()));

            if (!ShowYMetricPicker)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showYMetricPicker", ShowYMetricPicker.ToString().ToLower()));

            if (!ShowXScalePicker)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showXScalePicker", ShowXScalePicker.ToString().ToLower()));

            if (!ShowYScalePicker)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showYScalePicker", ShowYScalePicker.ToString().ToLower()));

            if (!ShowAdvancedPanel)
                scriptBuilder.AppendLine(string.Format(optionFormat, "showAdvancedPanel", ShowAdvancedPanel.ToString().ToLower()));

            return scriptBuilder.ToString();
        }
        #endregion
    }
}